﻿using System.Text.RegularExpressions;
using RpcHelper;

using RpcModel;

using Wedonek.RpcStore.Service.DAL;
using Wedonek.RpcStore.Service.Interface;
using Wedonek.RpcStore.Service.Model;

namespace Wedonek.RpcStore.Service.Collect
{
    internal class ServerTypeCollect : BasicCollect<RemoteServerTypeDAL>, IServerTypeCollect
    {

        public long Add(ServerTypeDatum add)
        {
            if (this.CheckIsRepeat(add.TypeVal))
            {
                throw new ErrorException("rpc.server.group.type.repeat");
            }
            return this.BasicDAL.AddServiceType(add);
        }
        public bool CheckIsRepeat(string typeVal)
        {
            return this.BasicDAL.CheckIsRepeat(typeVal);
        }

        public ServerType[] Gets(long groupId)
        {
            return this.BasicDAL.GetServiceTypes(groupId);
        }

        public void Set(long id, ServerTypeSetParam param)
        {
            this.BasicDAL.Set(id, param);
        }

        public void Drop(long id)
        {
            this.BasicDAL.Delete(id);
        }

        public ServerType Get(long id)
        {
            ServerType type = this.BasicDAL.Get(id);
            if (type == null)
            {
                throw new ErrorException("rpc.server.type.not.find");
            }
            return type;
        }

        public ServerType[] Query(ServerTypeQueryParam query, IBasicPage paging, out long count)
        {
            return this.BasicDAL.Query(query, paging, out count);
        }

        public ServerType[] Gets(long[] ids)
        {
            if (ids.Length == 0)
            {
                return System.Array.Empty<ServerType>();
            }
            return this.BasicDAL.Gets(ids);
        }

        public void Clear(long groupId)
        {
            this.BasicDAL.Clear(groupId);
        }

        public BasicServerType[] GetBasic(long[] ids)
        {
            return this.BasicDAL.GetBasic(ids);
        }
        public BasicServerType[] GetBasic(string[] types)
        {
            return this.BasicDAL.GetBasic(types);
        }

        public ServerType[] Gets(string[] types)
        {
            return base.BasicDAL.Gets(types);
        }
    }
}
